package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserData1;
import com.ruoyi.system.service.IUserData1Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户及数量Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Controller
@RequestMapping("/system/data1")
public class UserData1Controller extends BaseController
{
    private String prefix = "system/data1";

    @Autowired
    private IUserData1Service userData1Service;

    @RequiresPermissions("system:data1:view")
    @GetMapping()
    public String data1()
    {
        return prefix + "/data1";
    }

   // @RequiresPermissions("system:data1:view")
    @GetMapping("/show")
    public String data1_list()
    {
        return prefix + "/data2";
    }

    /**
     * 查询用户及数量列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserData1 userData1)
    {
        startPage(100);
        List<UserData1> list = userData1Service.selectUserData1List(userData1);
        return getDataTable(list);
    }

    /**
     * 导出用户及数量列表
     */
    @RequiresPermissions("system:data1:export")
    @Log(title = "用户及数量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserData1 userData1)
    {
        List<UserData1> list = userData1Service.selectUserData1List(userData1);
        ExcelUtil<UserData1> util = new ExcelUtil<UserData1>(UserData1.class);
        return util.exportExcel(list, "用户及数量数据");
    }

    /**
     * 新增用户及数量
     */
    @RequiresPermissions("system:data1:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户及数量
     */
    @RequiresPermissions("system:data1:add")
    @Log(title = "用户及数量", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserData1 userData1)
    {
        return toAjax(userData1Service.insertUserData1(userData1));
    }

    /**
     * 修改用户及数量
     */
    @RequiresPermissions("system:data1:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserData1 userData1 = userData1Service.selectUserData1ById(id);
        mmap.put("userData1", userData1);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户及数量
     */
    @RequiresPermissions("system:data1:edit")
    @Log(title = "用户及数量", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserData1 userData1)
    {
        return toAjax(userData1Service.updateUserData1(userData1));
    }

    /**
     * 删除用户及数量
     */
    @RequiresPermissions("system:data1:remove")
    @Log(title = "用户及数量", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userData1Service.deleteUserData1ByIds(ids));
    }
}
